package com.huanzhidadi.single.collection;

import java.util.*;
import java.util.stream.Collectors;

public class SetTest {
    public static void main(String[] args) {
        // HashSet： 无序
        Set<Integer> numberSet1 = new HashSet<>();
        numberSet1.add(46);
        numberSet1.add(12);
        numberSet1.add(66);
        System.out.println("numberSet1:" + numberSet1);

        // LinkedHashSet： 按照插入顺序
        Set<Integer> numberSet2 = new LinkedHashSet<>();
        numberSet2.add(46);
        numberSet2.add(12);
        numberSet2.add(66);
        System.out.println("numberSet2:" + numberSet2);

        // TreeSet： 从小到大排序
        Set<Integer> numberSet3 = new TreeSet<>();
        numberSet3.add(46);
        numberSet3.add(12);
        numberSet3.add(66);
        System.out.println("numberSet3:" + numberSet3);

        List<Integer> numberSet4 = numberSet3.stream().sorted((o1, o2) -> o1 > o2 ? -1 : 1).collect(Collectors.toList());
        System.out.println("numberSet4:" + numberSet4);

        char[] chars = String.valueOf(Math.PI).toCharArray();
        Set piSet = new LinkedHashSet<>();
        for (char c : chars) {
            piSet.add(c);
        }
        System.out.println("piSet:" + piSet);

    }
}
